package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.PrefectureRoot;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/11/3.
 */
public class PrefectureAdapter extends BaseAdapter {
    private Context context;
    private List<PrefectureRoot.DataEntity> entities;

    public PrefectureAdapter(Context context, List<PrefectureRoot.DataEntity> entities) {
        this.context = context;
        this.entities = entities;
    }


    @Override
    public int getCount() {
        return entities == null ? 0 : entities.size();
    }

    @Override
    public Object getItem(int position) {
        return entities == null ? null : entities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.prefecture_listview_item, null);
            holder = new ViewHolder();
            holder.prefeture_img = (ImageView) convertView.findViewById(R.id.prefeture_img);
            holder.prefeture_album_name = (TextView) convertView.findViewById(R.id.prefeture_album_name);
            holder.prefeture_album_desc = (TextView) convertView.findViewById(R.id.prefeture_album_desc);
            holder.read_count = (TextView) convertView.findViewById(R.id.read_count);

            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.prefeture_album_name.setText(entities.get(position).getName());
        holder.prefeture_album_desc.setText(entities.get(position).getDesc());
        holder.read_count.setText(String.valueOf(entities.get(position).getClickCount()));
        Picasso.with(context).load(entities.get(position).getPicUrl()).into(holder.prefeture_img);

        return convertView;
    }

    public class ViewHolder {
        private ImageView prefeture_img;
        private TextView prefeture_album_name, prefeture_album_desc, read_count;
    }


}
